package com.ruicar.afs.cloud.afscase.loanapprove.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ruicar.afs.cloud.afscase.approvemakelabel.entity.LoanLabelInfo;
import com.ruicar.afs.cloud.afscase.approvemakelabel.service.LoanLabelInfoService;
import com.ruicar.afs.cloud.afscase.loanapprove.condition.InvoiceInspectionCondition;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruicar.afs.cloud.afscase.loanapprove.service.CarInvoiceInfoService;
import com.ruicar.afs.cloud.afscase.loanapprove.vo.InvoiceInspectionVo;
import com.ruicar.afs.cloud.common.core.util.IResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author rongji.zhang
 * @Date 2020/9/2
 * @description
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/invoiceInspection")
@Api("发票验证")
public class InvoiceInspectionController {

    private CarInvoiceInfoService carInvoiceInfoService;

    private LoanLabelInfoService loanLabelInfoService;
    /**
     * 查询二次发票验证结果
     *
     * @param condition
     * @return
     */
    @PostMapping(value = "/getInvoiceList")
    @ApiOperation(value = "查询二次发票验证结果")
    public IResponse getInvoiceList(@RequestBody InvoiceInspectionCondition condition) {
        IPage<InvoiceInspectionVo> invoiceInspectionVoList = carInvoiceInfoService.getInvoiceList(new Page(condition.getPageNumber(),condition.getPageSize()),condition);
        invoiceInspectionVoList.getRecords().forEach(vo -> {
            /**标签信息表**/
            List<LoanLabelInfo> labelList = loanLabelInfoService.list(Wrappers.<LoanLabelInfo>query().lambda()
                    .eq(LoanLabelInfo::getApplyNo, vo.getApplyNo())
                    .eq(LoanLabelInfo::getContractNo, vo.getContractNo()));
            vo.setLabelList(labelList);
        });
        return IResponse.success(invoiceInspectionVoList);
    }

    /**
     * 查询所有二次发票验证结果
     *
     * @return
     */
    @PostMapping(value = "/getAllResultList")
    @ApiOperation(value = "查询所有二次发票验证结果")
    public IResponse getAllResultList(@RequestBody InvoiceInspectionCondition condition) {
        List<InvoiceInspectionVo> invoiceInspectionVoList = carInvoiceInfoService.getAllResultList(condition);
        return IResponse.success(invoiceInspectionVoList);
    }
}
